% setup env
clear all;
close all;
clc;

% schem parameter
R = 120;
L = 100e-6;
C = 33e-12;

% Resonance friquecy
f0 = 1 / (2*pi * sqrt(L*C));
fprintf('f0 = %f MHz\n', f0/1e6); 
%Discrete time
T = 10e-5 / f0;
Tmod = 20 / f0;

% time vector
t = 0:T:Tmod;

% init array
U = nan(1, length(t));
dU = nan(1, length(t));
I = nan(1, length(t));

% initial condition
U(1) = 0;
dU(1) = 0;
I(1) = 0;

% Gauss noise

E = 13 * randn(1, length(t));

U = nan(1, length(t));
dU = nan(1, length(t));
I = nan(1, length(t));

U(1) = 0;
dU(1) = 0;
I(1) = 0;

for k = 2:length(t)
    U(k) = U(k-1) + dU(k-1)*T;
    I(k) = I(k-1) + T*(E(k) - I(k-1)*R -U(k-1)) / L;
    dU(k) = I(k) / C;
end

% plottig
graphics_toolkit gnuplot

figure;
plot(t,E,t,U);
grid on
title('Gauss noise');
xlabel('t, s');
ylabel('U, V');
legend({'E(t)','U(t)'}, 'location', 'northeast');

print -deps -color "./Gauss.eps"
print -dpng -color "./Gauss.png"